<?php
 /**
 * Created by PhpStorm.
 * @package    art
 * @copyright  Copyright (c) 2013 LaZaDa SEA
 * @author     long.nguyen-thanh <long.nguyen-thanh@lazada.com
 * @date       5/20/14 5:28 PM
 * @ID         $Id$,${Id}
 */

$full_name 		= $this->formText('full_name',$this->Item['full_name'],array('class'=>'form-control', 'placeholder' => 'Full name', 'id' => 'item_full_name'));
$website 		= $this->formText('website',$this->Item['website'],array('class'=>'form-control', 'placeholder' => 'http://'));
$country 		= $this->formText('country',$this->Item['country'],array('class'=>'form-control', 'placeholder' => 'USA'));
$email 		    = $this->formText('email',$this->Item['email'],array('class'=>'form-control', 'placeholder' => 'Email'));
$city 		    = $this->formText('city',$this->Item['city'],array('class'=>'form-control', 'placeholder' => 'City'));
$cat_id			= $this->Item['cat_id'];


$arrRow = array(
    array('label'=>$this->translate('Full Name'),'input'=>$full_name),
    array('label'=>$this->translate('Website'),'input'=>$website, 'align' => 'horizontal'),
    array('label'=>$this->translate('Country'),'input'=>$country, 'align' => 'horizontal'),
    array('label'=>$this->translate('Email'),'input'=>$email, 'align' => 'horizontal'),
    array('label'=>$this->translate('City'),'input'=>$city, 'align' => 'horizontal')
);

$linkPost = $this->cmsUrl(array('action'=>'add-new-item'));


$linkLoadAjaxLogin = $this->cmsUrl(array(
										'module' => 'default',
										'controller' => 'index',
										'action' => 'ajax-login',
										'action-page' => 'add-new-item'
									));
									
$userInfo = new Zendvn_System_Info();
$userInfo = $userInfo->getMemberInfo();
if(empty($userInfo)){
	echo '<script>
			$(function(){
				$.get("' . $linkLoadAjaxLogin . '", function(data){
					$(".fancybox-inner").html(data);
				})
			})
		  </script>';
	
}else{
?>
<div class="row">
    <div class="box">
    	<div class="col-md-10 col-md-offset-1 list-error" id="list-error" style="display: none"></div>
    	<div class="clr"><h4 id="event_title" style="margin: 0px 0px 20px 0px; text-align: center">ADD YOUR NAME TO THE ARTSERV</h4></div>
		<form class="form-horizontal" role="form" id="appForm" name="appForm" action="<?php echo $linkPost?>" method="post">
			<?php
	            $html = '';
				$i = 0;
	            foreach($arrRow as  $val){
	            	$i++;
					$style = '';
					$styleLbl = '';
					if($i == 1){
						$style = ' style="width: 29.5%;"';
						$styleLbl = ' style="padding-left: 30px"';
					}
	            	$clssDiv = 'form-group has-feedback frm-input';
					$clssLabel = 'col-sm-2 control-label';
					$clssDivInput = 'col-sm-4';
	            	if(@$val['align'] == 'horizontal'){
	            		$clssDiv .= ' col-md-6';
	            		$clssLabel = 'col-md-4 col-xs-2 control-label';
						$clssDivInput .= ' column-input-4';
	            	}
	                $html.= '<div class="' . $clssDiv . '">
	                            <label class="' . $clssLabel . '" ' . $styleLbl . '>' . $val['label'] . '</label>
	                            <div class="' . $clssDivInput . '" ' . $style . '>' . $val['input'] . '</div>
	                        </div>';
	            }
	            echo $html;
	        ?>
	        <div class="form-group">
                <label id="lblGroup" for="full_name" class="col-sm-5 control-label"  style="padding-left: 30px">OCCUPATION [CHECK ALL THAT APPLY]</label>
            </div>
            <div class="form-group">
            	<label for="full_name" class="col-sm-2 control-label"></label>
	            <div class="col-sm-10"  id="ckbGroup">
	                <?php
		            if(!empty($this->slbCategory)){
		                $html = '';
		                foreach($this->slbCategory as  $val){
		                    $checked = '';
		                    if(@in_array($val['id'],$cat_id)) $checked = 'checked="checked"';
							$html.= '<div class="checkbox col-sm-3">
									    <label>
									      <input type="checkbox" '.$checked.' attr="'.$val['name'].'" name="cat_id[]" value="'.$val['id'].'" />'.$val['name'].'
									    </label>
									  </div>';
		                }
		                echo $html;
		            }
		            ?>
		      	</div>
		    </div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-9" style="text-align: right">
					<button type="submit" class="btn btn-default bg-blue">SUBMIT</button>
				</div>
			</div>
		</form>
	</div>
</div>

<script>
	$(function(){
		$(".fancybox-inner").niceScroll();

		$('#appForm').ajaxForm({ 
	        // dataType identifies the expected content type of the server response 
	        dataType:  'json', 
	 
	        // success identifies the function to invoke when the server response 
	        // has been received 
	        success: function(data){
	        	$('form[name="appForm"] div.frm-input').addClass('has-success');
	    		//$('form[name="appForm"] div.frm-input input').after('<span class="glyphicon glyphicon-ok form-control-feedback"></span>');
	    		$('#list-error').html('').hide();
				if(data.type == "error"){
					for(var x in data.msg){
						$('input#' + x).parent().parent().addClass('has-error');
						$('input#' + x).parent().find('span.glyphicon').removeClass('glyphicon-ok').addClass('glyphicon-remove');
						$('#list-error').append('<div class="alert alert-danger" id="list_device_alert"><strong>' + data.msg[x] + '</strong></div>');
					}
					$('#list-error').fadeIn();
				}else{
					$('form[name="appForm"] div.frm-input').removeClass('has-success').removeClass('has-error');
					$('span.form-control-feedback').remove();
					$('#appForm')[0].reset();
					$('#list-error').html('<div class="alert alert-success" id="list_device_alert"><strong>New name added successfully</strong></div>').fadeIn().delay(3000).fadeOut();
				}
	        } 
	    }); 
	})
	
</script>
<?php }?>